package sctu.edu.java.year2016.team02.project.pc.UI;

import sctu.edu.java.year2016.team02.project.pc.loginMan.PcOperator;
import sctu.edu.java.year2016.team02.project.pc.problem.PcProblem;
import sctu.edu.java.year2016.team02.project.pc.problem.SocketListener;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

/**
 * Created by Eoly on 2016/6/11.
 */
//对问题提交的提交界面
public class SubmitUI extends JDialog implements ActionListener{
    private JTextField MainMesField;
    private JTextArea DetailMesText;
    private JLabel MaMeMessage;
    private JLabel DeMeMessage;
    private Button submit;
    private PcOperator pc;

    public SubmitUI(JFrame praent, String title, PcOperator pc,boolean modal){
        super(praent,title,modal);
        this.pc=pc;
        Init();
        add(MainMesField);
        add(MaMeMessage);
        add(DetailMesText);
        add(DeMeMessage);
        add(submit);
        setLayout(null);

        setBounds(SocketListener.screenWidth / 3, SocketListener.ScreenHeight / 4, 600, 400);
        setResizable(false);
        setVisible(true);
    }

    private void Init(){
        MainMesField = new JTextField("");
        DetailMesText = new JTextArea("");
        MaMeMessage = new JLabel("问题主要描述：");
        DeMeMessage = new JLabel("问题详细描述：");
        submit = new Button("Submit");
        MaMeMessage.setBounds(75,45,100,25);
        MainMesField.setBounds(75,75,450,25);
        DeMeMessage.setBounds(75, 125, 100, 25);
        DetailMesText.setBounds(75,155,450,100);
        submit.setBounds(450,290,75,25);
        submit.addActionListener(this);
        DetailMesText.setLineWrap(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==submit) {
            PcProblem pb = new PcProblem();
            pb.setMainMessage(MainMesField.getText());
            pb.setDetailMessage(DetailMesText.getText());
            try {
                pb.inHand();//提交
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            JOptionPane.showMessageDialog(this, pb.getTipMessage(), "提示", JOptionPane.PLAIN_MESSAGE);
        }
    }
}
